/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * editarsemestre.java
 *
 * Created on 24-oct-2011, 2:30:50
 */

package proyectocatalina.mantenimiento;

import CapadeDatos.daosemestre2;
import java.awt.event.ActionEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import modelo.beansemestre;
import modelo.beancarrera;
import modelo.beanper;
import modelo.beanturno;
/**
 *
 * @author Vilma
 */
public class editarsemestre extends javax.swing.JInternalFrame{
String codsem="S-1";
beanper[] matriz2;
beanturno[] matriz3;
beancarrera[] matriz1;
    /** Creates new form editarsemestre */
    public editarsemestre() throws Exception {
        initComponents();
        ActionEvent e = null;
LogicadeNegocio.combocarrera1 carrera = new LogicadeNegocio.combocarrera1(jCombo);
carrera.cargarcarrera();
matriz1 = carrera.semestre();
jCombo.setSelectedIndex(0);
 if(newsemestreunidad.cod==null || newsemestreunidad.cod.equals("no habido") ){

cargar_semestre();
        }else {jtxtcodsem.setText(newsemestreunidad.cod);
jbtnbuscarsemActionPerformed( e );
        }
//  LogicadeNegocios.comboper per = new LogicadeNegocios.comboper(jcombo2);
//per.cargarper();
//matriz2 = per.semestre();
//jcombo2.setSelectedIndex(0);
  LogicadeNegocio.comboper per = new LogicadeNegocio.comboper(jcombo2);
per.cargarper();
matriz2 = per.semestre();
jcombo2.setSelectedIndex(0);

 LogicadeNegocio.comboturno1 turno = new LogicadeNegocio.comboturno1(jcombo3);
turno.cargarturno();
matriz3 = turno.semestre();
jcombo3.setSelectedIndex(0);


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jcombo3 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jcombo4 = new javax.swing.JComboBox();
        jcombo2 = new javax.swing.JComboBox();
        jCombo = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jDateini = new com.toedter.calendar.JDateChooser();
        jDatefin = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        jtxtfechaini = new javax.swing.JTextField();
        jtxtfechafin = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jtxtcodsem = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jbtnbuscarsem = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Editar Semestre"));

        jLabel2.setText("Periodo Lectivo");

        jcombo3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcombo3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcombo3ActionPerformed(evt);
            }
        });

        jLabel3.setText("Turno");

        jLabel1.setText("Carrera");

        jLabel4.setText("Semestre:");

        jcombo4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" }));

        jcombo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel6.setText("Fecha de Inicio:");

        jDateini.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jDateiniFocusLost(evt);
            }
        });

        jLabel7.setText("Fecha de Fin:");

        jLabel8.setText("FECH INI:");

        jLabel9.setText("FECH FIN:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDatefin, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                            .addComponent(jDateini, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jtxtfechaini, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(33, 33, 33)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                                .addComponent(jtxtfechafin, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jcombo2, 0, 312, Short.MAX_VALUE)
                                    .addComponent(jcombo4, 0, 312, Short.MAX_VALUE)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCombo, 0, 326, Short.MAX_VALUE)
                                    .addComponent(jcombo3, 0, 326, Short.MAX_VALUE))))))
                .addGap(14, 14, 14))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jcombo3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jcombo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcombo4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtfechaini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxtfechafin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jDateini, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7)
                    .addComponent(jDatefin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jtxtcodsem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtcodsemActionPerformed(evt);
            }
        });

        jLabel5.setText("CODIGO DE SEMESTRE :");

        jButton1.setText("Editar Semestre");
        jButton1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jbtnbuscarsem.setText("Buscar");
        jbtnbuscarsem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnbuscarsemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(42, 42, 42)
                .addComponent(jtxtcodsem, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbtnbuscarsem)
                .addContainerGap(89, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(245, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtcodsem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jbtnbuscarsem))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcombo3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcombo3ActionPerformed

        jcombo3.getItemAt(jcombo3.getSelectedIndex());
        // TODO add your handling code here:
}//GEN-LAST:event_jcombo3ActionPerformed

    private void jDateiniFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jDateiniFocusLost

        // TODO add your handling code here:
}//GEN-LAST:event_jDateiniFocusLost
String codcarr;
String codper;
int codturno=0;
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  
       Date ini = jDateini.getDate();
        Date fin = jDatefin.getDate();
        SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
        String fechaini = formato.format(ini);
        String fechafin = formato.format(fin);

        JOptionPane.showMessageDialog(null,"inicio-->"+fechaini+"       FIN---->"+fechafin);

        codcarr=matriz1[jCombo.getSelectedIndex()].getCodigo();

        codper=matriz2[jcombo2.getSelectedIndex()].getCod();

        codturno=matriz3[jcombo3.getSelectedIndex()].getCod_turno();
        CapadeDatos.daosemestre2 sem = new CapadeDatos.daosemestre2();
        sem.modsem(codsem,codturno,
                codper,
                codcarr,
                (String) jcombo4.getSelectedItem(),
                fechaini,
                fechafin
                );

        // TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed
beansemestre semestre;
    private void cargar_semestre() throws ParseException{
  //    Date ini = jDateini.getDate();
    //    Date fin = jDatefin.getDate();
//SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
String fechaini;
//= formato.format(ini);
String fechafin;
//= formato.format(fin);

    semestre=(beansemestre)daosemestre2.semestre(codsem);

    jCombo.setSelectedItem(semestre.getCod_carrera());
    jcombo2.setSelectedItem(semestre.getCod_per());
   jcombo3.setSelectedItem(semestre.getTurno());
jcombo4.setSelectedItem(semestre.getDescipcion());
fechaini=semestre.getFechaini();
fechafin=semestre.getFechafin();
jtxtfechaini.setText(fechaini);
jtxtfechafin.setText(fechafin);
//ini= formato.parse(fechaini);
//fin=formato.parse(fechafin);
//jDateini.setDateFormatString(fechaini);
//jDatefin.setDateFormatString(fechafin);

    }


    private void jtxtcodsemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtcodsemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtcodsemActionPerformed

    private void jbtnbuscarsemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnbuscarsemActionPerformed

            codsem = jtxtcodsem.getText();
        try {
            cargar_semestre();
            // TODO add your handling code here:
        } catch (ParseException ex) {
            Logger.getLogger(editarsemestre.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jbtnbuscarsemActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new editarsemestre().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(editarsemestre.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jCombo;
    private com.toedter.calendar.JDateChooser jDatefin;
    private com.toedter.calendar.JDateChooser jDateini;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton jbtnbuscarsem;
    private javax.swing.JComboBox jcombo2;
    private javax.swing.JComboBox jcombo3;
    private javax.swing.JComboBox jcombo4;
    private javax.swing.JTextField jtxtcodsem;
    private javax.swing.JTextField jtxtfechafin;
    private javax.swing.JTextField jtxtfechaini;
    // End of variables declaration//GEN-END:variables

}
